<?php
namespace Api\Utils;

use Utuo\DBRW;
class MicroShowUtil {
	
	/**
	 * 获得正在作业的微展示
	 */
	public static function getOnWork($cid, $openId) {
		DBRW::openAndClose(0);
		$myShow = M("MicroShow")->where("cid=%d and openId='%s' and status=0", $cid, $openId )->find();
		DBRW::openAndClose(1);
		return $myShow;
	}
	
	/**
	 * 设置已完成
	 */
	public static function finished( $cid, $id ) {
		return M("MicroShow")->where("cid=%d and id=%d", $cid, $id )->setField("status", 1);
	}
	
	/**
	 * 添加一个微展
	 */
	public static function addMyShow( $cid, $openId ) {
		return M("MicroShow")->add(array(
			'cid' => $cid,
			'openId' => $openId,
			'title' => '我的微秀',
			'createTime' => time(),
			'status' => 0,
			'is_deleted' => 0,
		    'tplId' => 1,
		    'musicId' => 3,
		));
	}
	
	/**
	 * 保存
	 * @param unknown $data
	 */
	public static function save( $data ) {
		return M("MicroShow")->save( $data );
	}
	
}